
const DTabsViews = {
    state: {
        contentTabs: [{name:'Home',path:'/index/home',label:'Home'}],        //tabs集合
        contentTabsActiveName:'Home'    //当前显示的集合
    },

    mutations: {
		//添加tabs
		ADD_CONTENTTABS: (state, view) => {
			if (state.contentTabs.some(v => v.name === view.name)) { return }
			state.contentTabs.push(view);
		},
		SET_CONTENTTABS:(state, val) => {
			state.contentTabs = val;
		},
		//设置当前显示的tab
        SET_CONTENTTABSACTIVENAME: (state, view) => {
            state.contentTabsActiveName = view.name
		},
		//delete tabs
		DELETE_CONTENTTABS: (state, view) => {
			if(view.name=='Home'){
				return
			}
			for (const [i, v] of state.contentTabs.entries()) {
				if ( v.name == view.name) {
					state.contentTabs.splice(i, 1)
					break
				}
        	}
		},
		DELETEALL_CONTENTTABS: (state) => {
			state.contentTabs  = state.contentTabs.filter(function (view) {
					return view.name =='Home';
					}
			)
   
		},
    },
    actions: {
        addContentTabs({dispatch,commit}, view) {
			commit('ADD_CONTENTTABS', view)
			dispatch('setContentTabsActivename' ,view)
		},
		setContentTabs({commit},val){
			commit('SET_CONTENTTABS',val);
		},
		setContentTabsActivename({commit}, view) {
        	commit('SET_CONTENTTABSACTIVENAME', view)
		},
		deleteConntenttabs({state,commit}, view){
			
			if(state.contentTabsActiveName == view.name){
					
			for (const [i, v] of state.contentTabs.entries()) {
				if ( v.name == view.name) {					
					commit('SET_CONTENTTABSACTIVENAME' ,state.contentTabs[i-1]);
					break
				}
        	}
			}
			commit('DELETE_CONTENTTABS', view)
		},
		
		deleteAllConntenttabs({state,commit}){
			commit('DELETEALL_CONTENTTABS' ) ;
			commit('SET_CONTENTTABSACTIVENAME' ,state.contentTabs[0])
		}
		

	}
	
}

export default DTabsViews
